package com.atguigu.java;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * @author : leimingchao
 * @date Date : 2021年10月06日 22:41
 */
public class PropertiesTest {

    /**
     * Properties：常用来处理配置文件。key和value都是String类型
     */
    public static void main(String[] args) {

        Properties properties = new Properties();
        FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream("jdbc.properties");
            //加载流对应的文件
            properties.load(fileInputStream);
            String name = properties.getProperty("name");
            Object password = properties.get("password");
            System.out.println("name = " + name + ", password = " + password);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fileInputStream != null) {
                try {
                    fileInputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
